import {createSlice,PayloadAction} from '@reduxjs/toolkit'
export type UserStateType={
  username:string, // user name for the user. 创建一个名为username的变量。 用户名可以在任务终
  nickname:string, // user nickname for the user. 创建一个名为nickname的变量。 用户名可以在任
}
const INIT_STATE:UserStateType={username:'',nickname:'',}// initial state for the user info. 创建一个名为INIT_STATET
export const userSlice=createSlice({
  name:'user',
  initialState:INIT_STATE,
  reducers:{
    loginReducer:(state:UserStateType,actions:PayloadAction<UserStateType>)=>{
      return actions.payload
    },
    logoutReducer:()=>INIT_STATE
  }
})
export  const {loginReducer,logoutReducer}=userSlice.actions
export default userSlice.reducer